<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!--导入easyui样式 -->
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/themes/bootstrap/easyui.css" />
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/themes/icon.css" />
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/jquery-1.9.1.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/easyui-lang-zh_CN.js"></script>
<title>订单展示</title>
</head>
<script type="text/javascript">
$(function () {
	$('#dg').datagrid({    
	    url:'yhorder_json.action',
	    columns:[[ 
	           {field:'ck',checkbox:true},
	    	   {field:'oid',title:'订单编号',width:80},    
	    	   {field:'sendname',title:'寄件人',width:80},
	    	   {field:'sendtel',title:'寄件人电话',width:133},
	    	   {field:'addressname',title:'收件人',width:80},    
	    	   {field:'addresstel',title:'收件人电话',width:133},
	    	   {field:'place',title:'发件地',width:80},
	    	   {field:'fhdate',title:'发货日期',width:120},    
	    	   {field:'receipt',title:'收件地',width:80},
	    	   {field:'paystate',title:'支付状态',width:80},
	    	   {field:'orderstatus',title:'订单状态',width:80},    
	    	   {field:'type',title:'订单类别',width:80},
	    	   {field:'goodsname',title:'物品名',width:80},
	    	   {field:'goodstype',title:'物品类别',width:80},    
	    	   {field:'weight',title:'物品重量',width:80},
	    	   {field:'volume',title:'物品体积',width:80},
	    	   {field:'tariff',title:'总费用',width:80},    
	    	   {field:'remarks',title:'备注',width:80},	    	       
	    	   ]] ,
	    	      fitColumns:true,
	    	      pagination:true,
	    	      pagePosition:'bottom',
	    	      pageSize:10,
	    	      pageList:[5,10,20],
	toolbar: [{
	//-------------------撤销-----------------
		iconCls: 'icon-edit',
		text:'撤销订单',
		handler: function(){
			var  orders = $('#dg').datagrid('getSelections');
			if(orders.length==1){
				if("未处理"==orders[0].orderstatus){
					$("#delorder").dialog("open").dialog('setTitle', '撤销订单'); 
					$('#scorder').text("确认撤销订单"+orders[0].oid);
					$("#dels").linkbutton({
						onClick:function(){	
							$.ajax({
								url:'cxorder.action',
								type:'post',
								data:{'oid':orders[0].oid,'ostatus':"已撤销"},
								dataType:'text',
								success:function(xx){
									if("1"==xx){
									$.messager.alert('信息','撤销成功','info');	
									$("#delorder").dialog("close");
									$('#scorder').text("");
				     				$('#dg').datagrid('reload');
									}else{
									$.messager.alert('信息','撤销失败，请重试','info');								
									$("#delorder").dialog("close");
									}
								}
							})	
						}
					});
			}else{
				$.messager.alert('信息','订单已处理，无法撤销','info');		
			}}else{
				$.messager.confirm('信息','请选择一张需要撤回的订单',function(r){    
				    if (r){    
				    	$('#dg').datagrid('uncheckAll');    
				    }    
				});
			}
		}		
	},'-',{
//----------------------------退订-----------------
		iconCls: 'icon-cancel',
		text:'取消订单',
		handler: function(){
			var  orders = $('#dg').datagrid('getSelections');
			if(orders.length==1){
				if("未处理"==orders[0].orderstatus||"已撤销"==orders[0].orderstatus||"已签收"==orders[0].orderstatus||"已退订"==orders[0].orderstatus)
				{
				$.messager.confirm('信息','该订单已签收或者未寄出，无法进行取消操作');
				}
				else{
					$("#remorder").dialog("open").dialog('setTitle', '取消订单'); 
					$('#fhorder').text("确认取消订单  "+ orders[0].oid);
					var order = JSON.stringify(orders[0]);
					$("#qxorder").val(order);
					$('#dle1').linkbutton({    
			    		onClick:function(){
			    		
			    			$("#tding").submit();		
			    		}
			    	})
					
				}
			}else{
				$.messager.confirm('信息','请选择一张需要退回的订单',function(r){    
				    if (r){    
				    	$('#dg').datagrid('uncheckAll');    
				    }    
				});
			}
		}
	},'-',{
	//------------------签收-----------------------
		iconCls: 'icon-ok',
		text:'签收订单',
		handler: function(){
			var  orders = $('#dg').datagrid('getSelections');
			if(orders.length==1){
				if("已送达"!=orders[0].orderstatus){
				$.messager.confirm('信息','该订单已签收或者未送达，无法进行签收操作');
				}
				else{
					$.messager.confirm('信息',"确认签收订单 "+orders[0].oid,function(r){    
					    if (r){
					    	$.ajax({
					    		url:'cxorder.action', 
					    		type:'post',
					    		data:{"oid":orders[0].oid,'ostatus':"已签收"},
					    		success:function(xx){ 	
					    			if(xx==null){
					    				$.messager.alert('error','签收失败！','info');							
					    			}else{
					    				$.messager.alert('信息',"订单 "+orders[0].oid+" 已成功签收！亲！记得付款哦",'info');		
					     				$('#dg').datagrid('reload');
					    			}
					    		
					    		}
					    	})
					    	   
					    }    
					});
					

					
				}
			}else{
				$.messager.confirm('信息','请选择一张需要签收的订单',function(r){    
				    if (r){    
				    	$('#dg').datagrid('uncheckAll');    
				    }    
				});
			}
		}
	}]

	    	}); 
//提交退订订单

$('#tding').form({
	url : 'tdingorder.action',
	success:function(xx){
			if(xx==null){
				$.messager.alert('error','取消失败！','info');							
			}else{
				$.messager.alert('信息',"取消成功,退订返回订单编号为 "+xx+"  ，请留意查看",'info');	
				$("#remorder").dialog("close");		
 				$('#dg').datagrid('reload');
			}
	}})
	
})
</script>
<body>
<table id="dg"></table> 
<!------------------------------------- 撤销订单 ----------------------------------------->
<div id="delorder" class="easyui-dialog"  closed="true" buttons="#dlg-buttons" > 
<div  style="width: 200px;height: 100px;margin-top: 30px;margin-left: 30px">
		<span id="scorder" ></span>
</div>
       <div id="del-buttons">
        <button id="dels"  class="easyui-linkbutton"  iconcls="icon-save">确认撤销</button>
        <a id="cancl" class="easyui-linkbutton" onclick="javascript:$('#delorder').dialog('close')"
         iconcls="icon-cancel">取消</a>
        </div>
</div>
<!------------------------------------- 取消订单 ----------------------------------------->
<div id="remorder" class="easyui-dialog"  closed="true" buttons="#dlg1-buttons" > 
<form id="tding" method="post">
<div  style="width: 200px;height: 100px;margin-top: 30px;margin-left: 30px">
		选择取消订单，将产生一张新的订单来返回原物件,并产生新的配送费用<br>
			<span id="fhorder" style="font-size: medium;font-style: oblique;"></span>
		<input id="qxorder" name="qxorder" style="display:none;">
</div>
       <div id="del1-buttons">
        <button id="del1"  class="easyui-linkbutton"  iconcls="icon-save">确认取消</button>
        <a id="cancl1" class="easyui-linkbutton" onclick="javascript:$('#remorder').dialog('close')"
         iconcls="icon-cancel">取消</a>
        </div>
</form>      
</div>
</body>
</html>